package com.zhaorui.controller;

import cn.hutool.core.bean.BeanUtil;
import com.zhaorui.aop.Annotation2;
import com.zhaorui.entity.ActivityDictionary;
import com.zhaorui.entity.ActivityTitlePrize;
import com.zhaorui.entity.ZR;
import com.zhaorui.form.DictionaryAddFrom;
import com.zhaorui.form.TitlePrizeAddForm;
import com.zhaorui.service.ActivityPrizeService;
import com.zhaorui.service.ActivityTitlePrizeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/activityTitlePrize")
@Slf4j
@CrossOrigin
@Api(tags = "奖品配置管理接口")
public class ActivityTitlePrizeController {
    @Autowired
    private ActivityTitlePrizeService activityTitlePrizeService;
    /**
     * 添加
     *
     * @param titlePrizeAddForm
     * @return
     */
    @PostMapping("/saveTitlePrize")
    @ApiOperation("增加")
    @Transactional//事务
    @Annotation2(tableName = "activity_title_prize", optionName = "增加")
    public ZR saveTitlePrize(@Valid @RequestBody TitlePrizeAddForm titlePrizeAddForm) {
        log.info ("开始新增*********************************");
//        ActivityDictionary activityDictionary = new ActivityDictionary ();
        ActivityTitlePrize activityTitlePrize=new ActivityTitlePrize ();
        BeanUtil.copyProperties (titlePrizeAddForm, activityTitlePrize);
        activityTitlePrizeService.saveTitlePrize (activityTitlePrize);
        return new ZR (1000, "增加成功", activityTitlePrize);
    }
}
